package com.wx.cloud.permission.service.impl;

import com.wx.cloud.permission.mapper.RoleMapper;
import com.wx.cloud.permission.model.Role;
import com.wx.cloud.permission.service.RoleService;
import com.wx.cloud.permission.utils.MyDate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;

@Service("roleService")
public class RoleServiceImpl implements RoleService {

    @Autowired
    private RoleMapper roleMapper;

    @Override
    public List<Role> getRoleList() {
        return roleMapper.getRoleList();
    }

    @Override
    public List<Role> getSelectList(Map<String, Object> data) {
        int page = Integer.parseInt((String) data.get("pageNum"));
        int size = Integer.parseInt((String)data.get("pageSize"));
        data.put("pageNum",(page-1)*size);
        data.put("pageSize",size);
        return roleMapper.getSelectList(data);
    }

    @Override
    public int getSelectCount(Map<String, Object> data) {
        return roleMapper.getSelectCount(data);
    }

    @Override
    public Role getRoleById(Integer id) {
        return roleMapper.getRoleById(id);
    }

    @Override
    public String addRole(Role role) {
        role.setCreateTime(MyDate.getDate());
        role.setUpdateTime(MyDate.getDate());
        int result = roleMapper.addRole(role);
        if (result>0){
            return "success";
        }else {
            return "false";
        }
    }

    @Override
    public int updateRole(Role role) {
        role.setUpdateTime(MyDate.getDate());
        return roleMapper.updateRole(role);
    }

    @Override
    public int delRole(Role role) {
        role.setUpdateTime(MyDate.getDate());
        return roleMapper.delRole(role);
    }

    @Override
    public int updateState(Role role) {
        role.setUpdateTime(MyDate.getDate());
        return roleMapper.updateState(role);
    }

}
